import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { Qrcode } from '@libs/db/models/qrcode.models';
import { Subcode } from '@libs/db/models/subcode.models';
import { InjectModel } from 'nestjs-typegoose';
import { ModelType } from '@typegoose/typegoose/lib/types';

@Injectable()
export class AppService {
    constructor(
        @InjectModel(Qrcode) private qrcodeModel: ModelType<Qrcode>,
        @InjectModel(Subcode) private SubcodeModel: ModelType<Subcode>
    ) { }


    @Cron('0 59 23 * * *')
    async handleCron() {
        await this.qrcodeModel.updateMany({}, { todayscann: 0, todayclick: 0 })
        await this.SubcodeModel.updateMany({}, { impression: 0, todayclick: 0 })
    }


}
